<?php 
/** 
 * 二叉树的深度
 * 
 */


class TreeNode{
    public $val;
    public $left = null;
    public $right = null;
    public function __construct($val){
        $this->val = $val;
    }
}


function TreeDepth($pRoot)
{
    if (!$pRoot) return 0;
    return max(1 + TreeDepth($pRoot->left), (1 + TreeDepth($pRoot->right)));
}


$node = new TreeNode(1);
$node->right = new TreeNode(2);
$node->left = new TreeNode(3);
$node->right->left = new TreeNode(4);
var_dump(TreeDepth($node));


